package com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype.infosecurityquery.activeresourcemonitorquery;

import com.zx.idc.backend.gui.api.commom.entity.CommandModel;
import com.zx.idc.backend.gui.api.management.infosecurity.activeresources.service.QueryViewService;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandOperating;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.SubCommandHandler;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.entity.Option;
import com.zx.idc.xml.entity.QueryView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import static com.zx.idc.common.attributes.SchemaFileNameAttributes.ACTIVE_RESOURCE_VIEWS_QUERY;

/**
 * Created by hasee on 2019/3/1.
 * 活跃资源访问量查询指令内容 11.19
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class ActiveResourceMonitorQueryImpl extends CommandOperating<QueryView> implements SubCommandHandler {

    private String schemaPath = getSchemaFilePath(ACTIVE_RESOURCE_VIEWS_QUERY);

    @Autowired
    private QueryViewService queryViewService;

    /**
     * 匹配方法
     *
     * @param xmlData
     * @return
     */
    @Override
    public boolean isMatch(String xmlData) {
        QueryView queryView = xml2Bean(xmlData, QueryView.class, schemaPath);
        return !ObjectUtils.isEmpty(queryView);
    }

    /**
     * 执行方法
     *
     * @param xmlData
     * @param commandModel
     * @return
     */
    @Override
    public String execute(String xmlData, CommandModel commandModel) {
        return receiveCommand(xmlData, commandModel, schemaPath);
    }


    /**
     * 覆盖该方法执行指令
     *
     * @param queryView    实体bean
     * @param commandModel 指令mode
     */
    @Override
    public void task(QueryView queryView, CommandModel commandModel) {
        queryViewService.queryView(queryView, commandModel);
    }
}
